package com.lollipop.synthential.algorithm;

import lombok.extern.slf4j.Slf4j;

import java.util.Random;

/**
 * @Author: J.K
 * @Date: 2022-07-29 14:16
 * @Description: 随机算法
 */
@Slf4j
public class RandomRibbon {
    public static String getServer(){
        Random random = new Random();
        // 从已配置的服务器列表中，随机抽取一个节点处理请求
        return Servers.SERVERS.get(random.nextInt(Servers.SERVERS.size()));
    }

    public static void main(String[] args) {
        // 模拟10个请求
        for (int i = 0; i < 10; i++) {
            log.info("第[{}]个请求，服务节点：[{}]", i, RandomRibbon.getServer());
        }
    }
}
